package com.ken.forum.controller;


import com.ken.forum.common.AppResult;
import com.ken.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1")
    @RequestMapping("/hello")  // 访问路径：/test/hello
    public String hello() {
        return "hello Springboot...";
    }


    // 注意：@ApiParam ⽅法参数的注解，⽤来描述参数
    @ApiOperation(value = "测试接⼝3，返回 你好+传⼊参数")
    @GetMapping("/helloByName")
    public AppResult<String> helloByName(@ApiParam(value = "名字", required = true) String name) {
        return AppResult.success("你好：" + name);
    }


    @ApiOperation("测试接口2,显示异常信息")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }

    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}
